package com.liuyonggang.generator.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.liuyonggang.generator.service.DbInfoApi;
import com.liuyonggang.generator.service.ProjectInfoApi;
import com.liuyonggang.generator.service.TemplateInfoApi;
import com.liuyonggang.generator.util.ResultVo;


@Controller
public class IndexAction {
    private static final Logger logger =LoggerFactory.getLogger(IndexAction.class);
    
    @Autowired
    private DbInfoApi dbInfoApi; 
    @Autowired
    private ProjectInfoApi projectInfoApi;
    @Autowired
    private TemplateInfoApi templateInfoApi;
    

    @RequestMapping(value = {"", "/"})
	public String page() {
		logger.info("欢迎使用本系统，进行代码生成器");
		return "/login";
	}
	
	@RequestMapping("/login")
	public String login(ModelMap map, @RequestParam(required = false) String username, 
	        @RequestParam(required = false) String password,HttpServletRequest request, HttpServletResponse response) {
		logger.info("登录用户名："+username+"密码： "+password+" 开始登录中。。。。");
		return "/index";
	}
	
	@RequestMapping("/login1")
	@ResponseBody
	public ResultVo login(@RequestParam String username, @RequestParam String password, HttpServletRequest request, HttpServletResponse response){
		ResultVo result = new ResultVo();
		if(StringUtils.isEmpty(username) || StringUtils.isEmpty(password)){
			result.setStatus(400);
			result.setMessage("账户和密码输入错误");
			return result;
		}
		return result;
	}
	

	@RequestMapping("/logout")
	public String logout(HttpServletRequest request, HttpServletResponse response){
		return "redirect:/";
	}
	
	//生成代码
	public ResultVo generator(){
	    ResultVo result = new ResultVo();
	    
	    
	    
	    return result;
	}
}
